package o;

import com.huawei.hms.aaid.constant.AaidIdConstant;
import com.huawei.hms.framework.network.restclient.hwhttp.trans.ByteString;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import javax.annotation.Nullable;

public class fxh implements Serializable, Comparable<fxh> {
    static final char[] ˎ = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    public static final fxh ˏ = ˎ(new byte[0]);
    final byte[] ˊ;
    transient String ˋ;
    transient int ॱ;

    public /* synthetic */ int compareTo(Object obj) {
        return ˊ((fxh) obj);
    }

    fxh(byte[] bArr) {
        this.ˊ = bArr;
    }

    public static fxh ˎ(byte... bArr) {
        if (bArr != null) {
            return new fxh((byte[]) bArr.clone());
        }
        throw new IllegalArgumentException("data == null");
    }

    public static fxh ˏ(String str) {
        if (str == null) {
            throw new IllegalArgumentException("s == null");
        }
        fxh o_fxh = new fxh(str.getBytes(fxy.ˊ));
        o_fxh.ˋ = str;
        return o_fxh;
    }

    public String ˊ() {
        String str = this.ˋ;
        if (str != null) {
            return str;
        }
        str = new String(this.ˊ, fxy.ˊ);
        this.ˋ = str;
        return str;
    }

    public String ˏ() {
        return fxf.ˏ(this.ˊ);
    }

    public fxh ˋ() {
        return ˎ("MD5");
    }

    public fxh ˎ() {
        return ˎ("SHA-1");
    }

    public fxh ॱ() {
        return ˎ(AaidIdConstant.SIGNATURE_SHA256);
    }

    private fxh ˎ(String str) {
        try {
            return ˎ(MessageDigest.getInstance(str).digest(this.ˊ));
        } catch (NoSuchAlgorithmException e) {
            throw new AssertionError(e);
        }
    }

    @Nullable
    public static fxh ॱ(String str) {
        if (str == null) {
            throw new IllegalArgumentException("base64 == null");
        }
        byte[] ˊ = fxf.ˊ(str);
        return ˊ != null ? new fxh(ˊ) : null;
    }

    public String ᐝ() {
        int i = 0;
        char[] cArr = new char[(this.ˊ.length * 2)];
        byte[] bArr = this.ˊ;
        int length = bArr.length;
        int i2 = 0;
        while (i < length) {
            byte b = bArr[i];
            int i3 = i2 + 1;
            cArr[i2] = ˎ[(b >> 4) & 15];
            i2 = i3 + 1;
            cArr[i3] = ˎ[b & 15];
            i++;
        }
        return new String(cArr);
    }

    public static fxh ˋ(String str) {
        if (str == null) {
            throw new IllegalArgumentException("hex == null");
        } else if (str.length() % 2 != 0) {
            throw new IllegalArgumentException("Unexpected hex string: " + str);
        } else {
            byte[] bArr = new byte[(str.length() / 2)];
            for (int i = 0; i < bArr.length; i++) {
                bArr[i] = (byte) ((ˊ(str.charAt(i * 2)) << 4) + ˊ(str.charAt((i * 2) + 1)));
            }
            return ˎ(bArr);
        }
    }

    private static int ˊ(char c) {
        if (c >= '0' && c <= '9') {
            return c - 48;
        }
        if (c >= 'a' && c <= 'f') {
            return (c - 97) + 10;
        }
        if (c >= 'A' && c <= 'F') {
            return (c - 65) + 10;
        }
        throw new IllegalArgumentException("Unexpected hex digit: " + c);
    }

    public static fxh ˋ(InputStream inputStream, int i) throws IOException {
        if (inputStream == null) {
            throw new IllegalArgumentException("in == null");
        } else if (i < 0) {
            throw new IllegalArgumentException("byteCount < 0: " + i);
        } else {
            byte[] bArr = new byte[i];
            int i2 = 0;
            while (i2 < i) {
                int read = inputStream.read(bArr, i2, i - i2);
                if (read == -1) {
                    throw new EOFException();
                }
                i2 += read;
            }
            return new fxh(bArr);
        }
    }

    public fxh ʻ() {
        int i = 0;
        while (i < this.ˊ.length) {
            byte b = this.ˊ[i];
            if (b < (byte) 65 || b > (byte) 90) {
                i++;
            } else {
                byte[] bArr = (byte[]) this.ˊ.clone();
                int i2 = i + 1;
                bArr[i] = (byte) (b + 32);
                for (i = i2; i < bArr.length; i++) {
                    byte b2 = bArr[i];
                    if (b2 >= (byte) 65 && b2 <= (byte) 90) {
                        bArr[i] = (byte) (b2 + 32);
                    }
                }
                return new fxh(bArr);
            }
        }
        return this;
    }

    public fxh ˎ(int i, int i2) {
        if (i < 0) {
            throw new IllegalArgumentException("beginIndex < 0");
        } else if (i2 > this.ˊ.length) {
            throw new IllegalArgumentException("endIndex > length(" + this.ˊ.length + ")");
        } else {
            int i3 = i2 - i;
            if (i3 < 0) {
                throw new IllegalArgumentException("endIndex < beginIndex");
            } else if (i == 0 && i2 == this.ˊ.length) {
                return this;
            } else {
                Object obj = new byte[i3];
                System.arraycopy(this.ˊ, i, obj, 0, i3);
                this(obj);
                return this;
            }
        }
    }

    public byte ˏ(int i) {
        return this.ˊ[i];
    }

    public int ʼ() {
        return this.ˊ.length;
    }

    public byte[] ॱॱ() {
        return (byte[]) this.ˊ.clone();
    }

    void ˊ(fxi o_fxi) {
        o_fxi.ˊ(this.ˊ, 0, this.ˊ.length);
    }

    public boolean ˏ(int i, fxh o_fxh, int i2, int i3) {
        return o_fxh.ॱ(i2, this.ˊ, i, i3);
    }

    public boolean ॱ(int i, byte[] bArr, int i2, int i3) {
        return i >= 0 && i <= this.ˊ.length - i3 && i2 >= 0 && i2 <= bArr.length - i3 && fxy.ˎ(this.ˊ, i, bArr, i2, i3);
    }

    public final boolean ˋ(fxh o_fxh) {
        return ˏ(0, o_fxh, 0, o_fxh.ʼ());
    }

    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        boolean z;
        if ((obj instanceof fxh) && ((fxh) obj).ʼ() == this.ˊ.length && ((fxh) obj).ॱ(0, this.ˊ, 0, this.ˊ.length)) {
            z = true;
        } else {
            z = false;
        }
        return z;
    }

    public int hashCode() {
        int i = this.ॱ;
        if (i != 0) {
            return i;
        }
        i = Arrays.hashCode(this.ˊ);
        this.ॱ = i;
        return i;
    }

    public int ˊ(fxh o_fxh) {
        int ʼ = ʼ();
        int ʼ2 = o_fxh.ʼ();
        int min = Math.min(ʼ, ʼ2);
        int i = 0;
        while (i < min) {
            int ˏ = ˏ(i) & 255;
            int ˏ2 = o_fxh.ˏ(i) & 255;
            if (ˏ == ˏ2) {
                i++;
            } else if (ˏ < ˏ2) {
                return -1;
            } else {
                return 1;
            }
        }
        if (ʼ == ʼ2) {
            return 0;
        }
        if (ʼ >= ʼ2) {
            return 1;
        }
        return -1;
    }

    public String toString() {
        if (this.ˊ.length == 0) {
            return "[size=0]";
        }
        String ˊ = ˊ();
        int ˏ = ˏ(ˊ, 64);
        if (ˏ != -1) {
            String replace = ˊ.substring(0, ˏ).replace("\\", "\\\\").replace("\n", "\\n").replace("\r", "\\r");
            if (ˏ < ˊ.length()) {
                return "[size=" + this.ˊ.length + " text=" + replace + "…]";
            }
            return "[text=" + replace + "]";
        } else if (this.ˊ.length <= 64) {
            return "[hex=" + ᐝ() + "]";
        } else {
            return "[size=" + this.ˊ.length + " hex=" + ˎ(0, 64).ᐝ() + "…]";
        }
    }

    static int ˏ(String str, int i) {
        int i2 = 0;
        int length = str.length();
        int i3 = 0;
        while (i2 < length) {
            if (i3 == i) {
                return i2;
            }
            int codePointAt = str.codePointAt(i2);
            if ((Character.isISOControl(codePointAt) && codePointAt != 10 && codePointAt != 13) || codePointAt == ByteString.REPLACEMENT_CHARACTER) {
                return -1;
            }
            i3++;
            i2 += Character.charCount(codePointAt);
        }
        return str.length();
    }

    private void readObject(ObjectInputStream objectInputStream) throws IOException {
        fxh ˋ = ˋ(objectInputStream, objectInputStream.readInt());
        try {
            Field declaredField = fxh.class.getDeclaredField("ˊ");
            declaredField.setAccessible(true);
            declaredField.set(this, ˋ.ˊ);
        } catch (NoSuchFieldException e) {
            throw new AssertionError();
        } catch (IllegalAccessException e2) {
            throw new AssertionError();
        }
    }

    private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
        objectOutputStream.writeInt(this.ˊ.length);
        objectOutputStream.write(this.ˊ);
    }
}
